/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication5;

/**
 *
 * @author Denise Carolina
 */
public class Animal {

    static int staticInt = 0;
    int regularInt = 2;
    static String sound;
    protected String name;

    Animal(){
        staticInt++;
        System.out.println("constructor Animal");
    }

    static void sound(){
        sound = "Sound";
        System.out.println("Animal does " + sound);
    }

    public void printName(){
        name = "No Name";
        System.out.println(name);
    }
}

class Dog extends Animal{

    Dog(){
        staticInt++; // I can access becase extending
        System.out.println("constructor DOG");
    }
    
    static void sound(){
       sound = "guau";
       System.out.println("dog does " + sound);
    }

    @Override
    public void printName() {
        name = "Coco";
        System.out.println(name);
    }


}

class tester{
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Static one:: " + Animal.staticInt);
        //System.out.println("Regular one:: "  + regularInt);

        new Animal().sound();
        new Dog().sound();
        new Animal().sound();
        ((Animal)new Dog()).sound();
        System.out.println("After 4 instances:: " + Animal.staticInt);

        // Animal cannot be casted to Dog
//        Dog[] animals = {((Dog)new Animal()), new Dog(),((Dog) new Animal())};
        Animal[] animals = {new Animal(), new Dog(),new Animal()};
        for(Animal a : animals){
           a.sound(); // Will always print type animal because is static and are not overriden
           a.printName();
        }
    }

}
